package com.kgc.controller;

import com.kgc.bean.CarouselDTO;
import com.kgc.bean.GoodsItem;
import com.kgc.service.ShowHomeSildeshowService;
import com.kgc.util.ResultBuildUtil;
import com.kgc.util.ReturnResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created on 2021/6/23.
 * Author: lzy
 * Description:展示首页轮播图
 */
@RestController
@Api(tags = "展示首页轮播图入口")
@Slf4j
public class ShowHomeSildeshowController {


    @Autowired
    private ShowHomeSildeshowService showHomeSildeshowService;

    /**
     * @ClassName: ShowHomeSildeshowController
     * @Description 展示首页
     * @Author lzy
     * @Date 2021/6/23
     */

    @GetMapping("/getShowSildeshow")
    @ApiOperation(value = "轮播图展示", notes = "可以根据要求展示对应数量的轮播图")
    @ApiResponses({
            @ApiResponse(code = 6990, message = "查询轮播图失败"),
            @ApiResponse(code = 0000, message = "成功")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "count", required = true, value = "展示的数量", defaultValue = "5")
    })
    public ReturnResult<List<CarouselDTO>> showSildeshow(@RequestParam Integer count) {
        // 查询轮播图
        if (showHomeSildeshowService.querySelectSildeshow(count).size() > 0) {
            return ResultBuildUtil.success(showHomeSildeshowService.querySelectSildeshow(count));
        }
        return ResultBuildUtil.fail("6990", "查询轮播图失败");
    }

    /**
     *@ClassName: ShowHomeSildeshowController
     *@Description 点击轮播图，展示对应类型的商品
     *@Author lzy
     *@Date 2021/6/24
     */
   /* @GetMapping("/showGoodsByParentId")
    @ApiOperation(value = "通过点击轮播图跳转展示对应的商品",notes = "需要携带轮播图的类型参数，带分页，默认先展示10条")
    @ApiResponses({
            @ApiResponse(code = 6989,message = "无对应商品"),
            @ApiResponse(code=0000,message = "查询成功")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", required = true, value = "商品类型id")
            ,@ApiImplicitParam(name = "pageNo",required = true,value = "当前页码",defaultValue = "1")
            ,@ApiImplicitParam(name = "pageSize",required = true,value = "每页展示数量",defaultValue = "10")})
    public ReturnResult<List<GoodsItem>> showSildeshow(@RequestParam Integer parentId,
                                                       @RequestParam Integer pageNo,
                                                       @RequestParam Integer pageSize){
        // 查询轮播图
       if(showHomeSildeshowService.querySelectGoodsItem(parentId,pageNo,pageSize).size() > 0){
           log.info("--------- 根据轮播图查询的商品数量 ：{}",showHomeSildeshowService.querySelectGoodsItem(parentId,pageNo,pageSize).size());

          return ResultBuildUtil.success(showHomeSildeshowService.querySelectGoodsItem(parentId,pageNo,pageSize));

       }
        return ResultBuildUtil.fail("6989","无对应商品");
    }*/


}
